'use strict';

import Base from './base.js';

export default class extends Base {

  async listAction(){
    let model = this.model("flower");
    let typeId=this.get("typeId");
    let orderType=this.get("orderType");
    let orderStr="";
    let keyWord=this.get("keyWord");
    let condition={}
    if(keyWord&&keyWord!=""){
      condition["name"]= ["like", "%"+keyWord+"%"];
    }
    if(typeId&&typeId!=0){
      condition["typeId"]= typeId;
    }
    if(orderType==0){
      orderStr=" views desc,sales desc "
    }else if(orderType==1){
      orderStr=" sales desc "
    }else if(orderType==2){
      orderStr=" price asc "
    }else if(orderType==3){
      orderStr=" price desc "
    }
    let data = await model.where(condition).order(orderStr).page(this.get("page"), 10).countSelect();
    this.success(data);
  }

  async imgAction(){
    let flower = this.model("flower");
    let model = this.model("flower_Img");
    let id=this.get("id");
    let flowerData=await flower.where({id: id}).find();
    let data = await model.where({flowerId: id}).select();
    flowerData["imgItems"]=data;
    this.success(flowerData);
  }

  async typeAction(){
    let model = this.model("flower_type");
    let data = await model.select();
    this.success(data);
  }
}
